package com.fms.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fms.sys.entity.BlogCategory;
import com.fms.sys.mapper.BlogCategoryMapper;
import com.fms.sys.service.IBlogCategoryService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class BlogCategoryServiceImpl extends ServiceImpl<BlogCategoryMapper, BlogCategory>
        implements IBlogCategoryService {

    @Override
    public Page<BlogCategory> getCategoryList(Page<BlogCategory> page, String name) {
        LambdaQueryWrapper<BlogCategory> wrapper = new LambdaQueryWrapper<>();
        if (!StringUtils.isEmpty(name)) {
            wrapper.like(BlogCategory::getName, name);
        }
        wrapper.orderByAsc(BlogCategory::getSort);
        return this.page(page, wrapper);
    }

    @Override
    public boolean addCategory(BlogCategory category) {
        return this.save(category);
    }

    @Override
    public boolean updateCategory(BlogCategory category) {
        return this.updateById(category);
    }

    @Override
    public boolean deleteCategory(Long id) {
        return this.removeById(id);
    }

    @Override
    public BlogCategory getCategoryById(Long id) {
        return this.getById(id);
    }
}
